package it.xiuxian.personcenter.presenter

import com.lzy.okgo.OkGo
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.EncodeUtils
import it.xiuxian.lib.utils.ToastUtil
import it.xiuxian.personcenter.activity.GongXianActivity
import it.xiuxian.personcenter.bean.GongXianBean
import it.xiuxian.personcenter.bean.GongXianItemBean
import org.json.JSONObject

class GongXianActivityPresenter:BasePresenter<GongXianActivity>() {
    fun getGongXian(){
        OkGo.post<BaseBean<GongXianBean>>(HttpConfig.BASE_URL+"/appgongyichi/get")
            .execute(object : CallBackOption<BaseBean<GongXianBean>>() {}.loadBind(mView as GongXianActivity).execute(
                object : ILoadBind<BaseBean<GongXianBean>> {
                    override fun excute(bean: BaseBean<GongXianBean>) {
                        if(bean.code==0){
                            (mView as GongXianActivity).setUI(bean.data)
                        }
                    }
                }
            ))
    }
    fun getList(){
        OkGo.post<BaseBean<GongXianItemBean>>(HttpConfig.BASE_URL+"/apppaihangbang/juanxianzongbang")
            .execute(object : CallBackOption<BaseBean<GongXianItemBean>>() {}.loadBind(mView as GongXianActivity).execute(
                object : ILoadBind<BaseBean<GongXianItemBean>> {
                    override fun excute(bean: BaseBean<GongXianItemBean>) {
                        if(bean.code==0){
                            (mView as GongXianActivity).setList(bean.data)
                        }
                    }
                }
            ))
    }
       fun submit(gongxianzhi:String){
       var json1 = JSONObject()
       json1.put("gongxianzhi",gongxianzhi)

       OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appgongyichi/juanxian")
           .params("encrypt", EncodeUtils.encodeAES(json1.toString()))
           .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as GongXianActivity).execute(
               object : ILoadBind<BaseBean<String>> {
                   override fun excute(bean: BaseBean<String>) {
                       if(bean.code==0){
                          // ToastUtil.showShort(bean.msg)
                          (mView as GongXianActivity).setdata(bean.msg)
                       }
                   }
               }
           ))
   }
}